﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;

namespace HCFramework.AdminTool.VisitorLogViewer
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HCDataContext db = new HCDataContext();
                int current = db.VisitorLogs.Where(ik =>
                    ik.Date >= DateTime.Now.AddMinutes(-30))
                    .Count();
                int today = db.VisitorLogs.Where(ik =>
                    ik.Date >= DateTime.Now.AddDays(-1))
                    .Count();
                int thisWeek = db.VisitorLogs.Where(ik =>
                    ik.Date >= DateTime.Now.AddDays(-7))
                    .Count();
                int thisMonth = db.VisitorLogs.Where(ik =>
                    ik.Date >= DateTime.Now.AddDays(-30))
                    .Count();
                int prevMonth = db.VisitorLogs.Where(ik =>
                    ik.Date >= DateTime.Now.AddDays(-60))
                    .Count();
                int thisYear = db.VisitorLogs.Where(ik =>
                    ik.Date >= DateTime.Now.AddDays(-365))
                    .Count();
                int all = db.VisitorLogs.Count();

                litOnline.Text = current.ToString();
                litToday.Text = today.ToString();
                litThisWeek.Text = thisWeek.ToString();
                litThisMonth.Text = thisMonth.ToString();
                litPreviousMonth.Text = prevMonth.ToString();
                litThisYear.Text = thisYear.ToString();
                litAll.Text = all.ToString();
            }
        }
    }
}